package lang

import (
	"fmt"
	"reflect"
)

type Vertex struct {
	X int
	Y int
	Z func(a, b int, z float64, opt ...interface{}) (success bool)
}

type Locker interface {
	Lock()
	Unlock()
}

func mainDataTypes() {

	initBool()
	initDecimal()
	initString()
	initArray()
	initSlice()
	initStruct()
	initPointer()
	initMap()
	initChan()
}

func initBool() {
	// 传统的定义变量方式
	var var_bool bool
	fmt.Println(var_bool)

	// 类型推测
	var_bool2 := true // bool
	fmt.Println(var_bool2)
}

func initDecimal() {
	// 数类型
	var var_decimal uint8 // the set of all unsigned  8-bit integers (0 to 255)
	fmt.Println(var_decimal)
	var var_decimal2 int16 = 0 // the set of all unsigned 16-bit integers (0 to 65535)
	fmt.Println(var_decimal2)
	var var_decimal3 int32 = 123_456_789 // the set of all unsigned 32-bit integers (0 to 4294967295)
	fmt.Println(var_decimal3)
	var var_decimal4 int64 = 0 // the set of all unsigned 64-bit integers (0 to 18446744073709551615)
	fmt.Println(var_decimal4)

	var var_int8 int8 = 0 // the set of all signed  8-bit integers (-128 to 127)
	fmt.Println(var_int8)
	var var_int16 int16 = 0 // the set of all signed 16-bit integers (-32768 to 32767)
	fmt.Println(var_int16)
	var var_int32 int32 = 0 // the set of all signed 32-bit integers (-2147483648 to 2147483647)
	fmt.Println(var_int32)
	var var_int64 int64 = 0 // the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)
	fmt.Println(var_int64)

	var var_float32 float32 = 0 // the set of all IEEE-754 32-bit floating-point numbers
	fmt.Println(var_float32)
	var var_float64 float64 = 0 // the set of all IEEE-754 64-bit floating-point numbers
	fmt.Println(var_float64)

	var var_complex64 complex64 = 1 + 1i // the set of all complex numbers with float32 real and imaginary parts
	fmt.Println(var_complex64)
	var var_complex128 complex128 = 0 - 1i // the set of all complex numbers with float64 real and imaginary parts
	fmt.Println(var_complex128)

	// byte         alias for uint8
	// rune         alias for int32 字符
	// uint         (architecture depended) either 32 or 64 bits
	// int          (architecture depended) same size as uint
	// uintptr      (architecture depended) an unsigned integer large enough to store the uninterpreted bits of a pointer value

}
func initString() {
	// 字符串类型
	var_str := "'abc'\n"
	fmt.Println(var_str)
	// 原生字符串定义
	var_str2 := `a
b`
	fmt.Println(var_str2)
}

func initArray() {
	// 数组
	var var_array = []int32{0, 1, 2}
	fmt.Println(var_array)
	fmt.Println(var_array[0])
}

func initSlice() {
	// 切片类型(slice)
	var_slice := make([]int, 5, 10)
	fmt.Println(var_slice)
	var_slice2 := new([10]int)[0:5]
	fmt.Println("Var Slice:", reflect.TypeOf(var_slice2).Kind())
}

func initStruct() {
	// struct
	var var_struct = Vertex{1, 2, nil}
	fmt.Println(var_struct)
}

func initPointer() {
	// 指针类型
	var var_pointer *int = new(int)
	*var_pointer = 100
	fmt.Println(*var_pointer)
}

func initMap() {
	// Map 类型
	var var_map map[string]int = make(map[string]int)
	var_map["a"] = 1
	fmt.Println(var_map)

	// Map 类型: 复合初始化方式(composite literal)
	var var_map2 map[string]int = map[string]int{
		"a": 1,
		"b": 2,
	}
	fmt.Println(var_map2)
}

func initChan() {
	// Channel 类型
	var var_chan chan int32 = make(chan int32, 100) // can be used to send and receive values of type T
	fmt.Println(var_chan)
	// chan<- float64  // can only be used to send float64s
	// <-chan int      // can only be used to receive ints
}
